<template>
  <div ref="editor">打包vue处</div>
</template>

<script>
  // import '../../../static/ueditor.config'
  // import '../../../static/ueditor.parse'
  // import '../../../static/lang/zh-cn/zh-cn'
  // import { generateRandonInteger } from '../../../vuex/utils';
  // import { generateRandonInteger } from '../../../vuex/utils';
  export default {
    name: "ueditor",
    props:['value','config'],
    data() {
      return {
        id: generateRandonInteger(100000) + 'ueditorId'
      }
    },
    // props: {
    //   value: {
    //     type: String,
    //     default: null
    //   },
    //   config: {
    //     type: Object,
    //     default: {}
    //   }
    // },
    created(){
      console.log('===================================',this.value)
      console.log(this.config)
    },
    watch: {
      value: function value(val, oldVal) {
        this.editor = UE.getEditor(this.id, this.config)
        if (val !== null) {
          this.editor.setContent(val)
        }
      }
    },
    mounted() {
      this.$nextTick(function f1() {
        // 保证 this.$el 已经插入文档
        this.$refs.editor.id = this.id
        this.editor = UE.getEditor(this.id, this.config)
        this.editor.ready(function f2() {
          this.editor.setContent(this.value)
          this.editor.addListener("contentChange", function () {
            const wordCount = this.editor.getContentLength(true);
            const content = this.editor.getContent()
            const plainTxt = this.editor.getPlainTxt()
            this.$emit('input', { wordCount: wordCount, content: content, plainTxt: plainTxt })
          }.bind(this))
          this.$emit('ready', this.editor)
        }.bind(this))
      })
    }
  }
</script>

<style scoped>

</style>
